const api = require('../../utils/api.js');
const app = getApp();

Page({
  onUnload() {
    wx.setStorageSync('cancel', true);
  },

  getinfo(e) {
    if (e.detail.errMsg === 'getUserInfo:ok') {
      let userInfor = wx.getStorageSync('user_info');
      app.ws_micro_shoprequest({
        url: api.passport.info,
        data: {
          user_info: JSON.stringify(e.detail.userInfo),
          encrypted_data: e.detail.encryptedData,
          iv: e.detail.iv,
        },
        method: 'POST',
        success: function(res) {
          if (res.code === 0) {
            wx.showToast({
              title: '授权成功',
            });
            userInfor.unionid = res.data.unionid;
            userInfor.info = 1;
            wx.setStorageSync('user_info', userInfor);
            wx.navigateBack();
          }
        },
      });
    }
  },
});
